package pearson.automation.forms;

import org.openqa.selenium.By;

import framework.elements.ElementList;
import framework.elements.Label;

/**
 * Activity Stream form.
 */
public class ActivityStreamForm extends BaseFormWithSidebarsAndSearch {

    private static Label identifier =
        new Label(By.id("content-padding"), "Activity Stream");
    private ElementList courses =
        new ElementList(By.xpath("//div[@class='course-wall-module contain']"),
                        "Courses");   
    /**
     * Constructor.
     */
    public ActivityStreamForm() {
        super(identifier.getLocator(), "Activity Stream");
    }
    
    /**
     * Get activity stream course object by course ref.
     * @param courseRef String with course id
     * @return activity stream course object
     */
    public ActivityStreamCourse getCourse(String courseRef){
        return new ActivityStreamCourse(courseRef);
    }
    
    /**
     * Get course id from wall by index.
     * @param index number of the course on the wall
     * @return String with course ID
     */
    public String getCourseRefByID(int index){
        Label tempCourse = new Label(
                By.xpath(String.format(
                    "(//div[@class='course-wall-module contain'])[%d]", index)),
                "Activity Stream Course");
        return tempCourse.getElement().getAttribute("data-course-ref");
    }
    
    /**
     * Get number of courses on Activity Stream
     * @return number of courses
     */
    public int getCourseLength(){
        return courses.getListElements().size();
    }
}
